/*
 * Created by JFormDesigner on Thu Dec 12 23:52:34 CST 2024
 */

package com.hafu.view.kehu;

import com.hafu.dao.KhinfoDao;
import com.hafu.model.Khinfo;
import com.hafu.service.KhinfoService;
import com.hafu.service.KhinfoService;
import com.hafu.util.StringUtil;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.GroupLayout;

/**
 * @author DELL
 */
public class AddKeHuFrm extends JFrame {
    private KhinfoService khinfoService = new KhinfoService();
    private Object Khinfo;

    public AddKeHuFrm() {
        initComponents();
    }

    private void button1(ActionEvent e) {
        // TODO add your code here 添加客户信息事件
        String name = textField3.getText();
        String tel = textField4.getText();
        if (StringUtil.isEmpty(name)){
            JOptionPane.showMessageDialog(null, "客户姓名不能为空");
            return;
        }
        if (StringUtil.isEmpty(tel)){
            JOptionPane.showMessageDialog(null, "客户电话不能为空");
            return;
        }
        Khinfo khinfo = new Khinfo(name, tel);
        Boolean aBoolean = KhinfoService.addkhinfo(khinfo);
        if (aBoolean){
            JOptionPane.showMessageDialog(null, "添加成功");
            this.dispose();
        }else {
            JOptionPane.showMessageDialog(null, "添加失败");
        }

    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents  @formatter:off
        label1 = new JLabel();
        label2 = new JLabel();
        textField3 = new JTextField();
        textField4 = new JTextField();
        button1 = new JButton();

        //======== this ========
        setTitle("\u6dfb\u52a0\u5ba2\u6237\u8868\u5355");
        Container contentPane = getContentPane();

        //---- label1 ----
        label1.setText("\u5ba2\u6237\u540d\u5b57");

        //---- label2 ----
        label2.setText("\u5ba2\u6237\u7535\u8bdd");

        //---- button1 ----
        button1.setText("\u63d0\u4ea4");
        button1.addActionListener(e -> button1(e));

        GroupLayout contentPaneLayout = new GroupLayout(contentPane);
        contentPane.setLayout(contentPaneLayout);
        contentPaneLayout.setHorizontalGroup(
            contentPaneLayout.createParallelGroup()
                .addGroup(contentPaneLayout.createSequentialGroup()
                    .addGroup(contentPaneLayout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
                        .addGroup(contentPaneLayout.createSequentialGroup()
                            .addGap(60, 60, 60)
                            .addGroup(contentPaneLayout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
                                .addComponent(label1, GroupLayout.DEFAULT_SIZE, 61, Short.MAX_VALUE)
                                .addComponent(label2, GroupLayout.DEFAULT_SIZE, 61, Short.MAX_VALUE))
                            .addGap(44, 44, 44)
                            .addGroup(contentPaneLayout.createParallelGroup()
                                .addComponent(textField4)
                                .addComponent(textField3)))
                        .addGroup(contentPaneLayout.createSequentialGroup()
                            .addGap(111, 111, 111)
                            .addComponent(button1, GroupLayout.PREFERRED_SIZE, 292, GroupLayout.PREFERRED_SIZE)))
                    .addContainerGap(200, Short.MAX_VALUE))
        );
        contentPaneLayout.setVerticalGroup(
            contentPaneLayout.createParallelGroup()
                .addGroup(contentPaneLayout.createSequentialGroup()
                    .addGap(46, 46, 46)
                    .addGroup(contentPaneLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                        .addComponent(textField3, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                        .addComponent(label1))
                    .addGap(18, 18, 18)
                    .addGroup(contentPaneLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                        .addComponent(textField4, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                        .addComponent(label2))
                    .addGap(85, 85, 85)
                    .addComponent(button1)
                    .addContainerGap(155, Short.MAX_VALUE))
        );
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents  @formatter:on
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables  @formatter:off
    private JLabel label1;
    private JLabel label2;
    private JTextField textField3;
    private JTextField textField4;
    private JButton button1;
    // JFormDesigner - End of variables declaration  //GEN-END:variables  @formatter:on
}
